home *** CD-ROM | disk | FTP | other *** search
- PAGE 64,132
- TITLE ASK.COM Set Error Level from keyboard for Batch file use.
- ;------------------------------------------------------------------------
- ; Published in Programmers Journal Vol 3, No. 2 by Dan Rollins ;
- ; Modified for both IBM and Victor 9000 compatibility ;
- ; by Guy Gordon 6/4/85 ;
- ; ;
- ; Batch file utility sets ERRORLEVEL according to user input ;
- ; ;
- ; sytax: ;
- ; ;
- ; ASK prompt-string ;
- ; ;
- ; The prompt-string is displayed followed by 1 space, then the ;
- ; program pauses till a key is pressed. If the key is acceptable ;
- ; it is displayed, (followed by CR) and ERRORLEVEL is set. ;
- ; Otherwise a beep is sounded and the program continues to wait. ;
- ; ;
- ; valid | returned ;
- ; replies | ERRORLEVEL ;
- ; ------------------------ ;
- ; ESC | 0 ;
- ; 0 q Q F10 | 0 ;
- ; 1 y Y F1 | 1 ;
- ; 2 n N F2 | 2 ;
- ; 3 F3 | 3 ;
- ; . . | . ;
- ; . . | . ;
- ; 9 F9 | 9 ;
- ; ;
- ; Example usage in a batch file: ;
- ; ;
- ; echo off ;
- ; :start BASCOM compile & link with optional re-edit ;
- ; bascom %1; ;
- ; ask Re-edit source code (Y/N)? ;
- ; if errorlevel 2 goto continue ;
- ; rem control falls through when user answers Y ;
- ; edlin %1.BAS ;
- ; goto start ;
- ; :continue This branch taken when user answers N ;
- ; link %1; ;
- ; ;
- ;------------------------------------------------------------------------
-
- CODE SEGMENT PARA
- ASSUME CS:CODE, DS:CODE, ES:CODE, SS:CODE
-
- ORG 100H
- ASK PROC NEAR
- JMP START
-
- ;------------------------------------------------------------------------
- ; These tables have three bytes per element: ;
- ; 1. the ASCII input value ;
- ; 2. the exit code returned to DOS ;
- ; 3. the character to display ;
- ;------------------------------------------------------------------------
- NORMAL_KEYS LABEL BYTE ;non-extended ASCII table
- DB 'Q',0,'Q', 'q',0,'Q', 27,0,'q' ;last is Esc
- DB 'Y',1,'Y', 'y',1,'Y', '1',1,'1'
- DB 'N',2,'N', 'n',2,'N', '2',2,'2'
- DB '3',3,'3', '4',4,'4', '5',5,'5'
- DB '6',6,'6', '7',7,'7', '8',8,'8', '9',9,'9','0',0,'0'
-
- DB 0F1H,1,'1', 0F2H,2,'2', 0F3H,3,'3' ;Victor fn keys
- DB 0F4H,4,'4', 0F5H,5,'5', 0F6H,6,'6'
- DB 0F7H,7,'7', 0F8H,8,'8', 0F9H,9,'9', 0FAH,0,'0'
-
- DB 0B1H,1,'1', 0B2H,2,'2', 0B3H,3,'3' ;Victor fn keys
- DB 0B4H,4,'4', 0B5H,5,'5', 0B6H,6,'6'
- DB 0B7H,7,'7', 0B8H,8,'8', 0B9H,9,'9', 0BAH,0,'0'
-
- NK_LEN EQU ($ - NORMAL_KEYS)/3 ;count of 3-byte elements in table
-
- FN_KEYS LABEL BYTE ;extended ASCII
- DB 59,1,'1', 60,2,'2', 61,3,'3', 62,4,'4', 63,5,'5' ;fn keys
- DB 64,6,'6', 65,7,'7', 66,8,'8', 67,9,'9', 68,0,'0'
-
- DB 79,1,'1', 80,2,'2', 81,3,'3', 75,4,'4', 73,5,'5' ;num pad
- DB 77,6,'6', 71,7,'7', 72,8,'8', 73,9,'9', 82,0,'0'
-
- FK_LEN EQU ($ - FN_KEYS)/3 ;count of 3-byte elements in table
-
- BAD_VER_MSG DB 'Wrong DOS version', 0Dh, 0Ah, '$'
-
- ;------------------------------------------------------------------------
-
- ; CHECK IF DOS 2.X
-
- START: MOV AH,30h ;get DOS version number
- INT 21h ;
- CMP AL,2 ;at least version 2.0?
- JAE A10 ; yes, go
- MOV DX,OFFSET BAD_VER_MSG ; no,
- MOV AH,9 ; display message
- INT 21h ; and
- INT 20h ; exit
-
- ; DISPLAY PROMPT STRING
-
- A10: MOV SI,80h ;point to parameter string
- MOV CL,[SI] ;get length
- INC SI ;
- MOV CH,0 ;
- ADD SI,CX ;find end of prompt string
- MOV BYTE PTR [SI],' ' ;add a space
- MOV BYTE PTR [SI+1],'$' ;terminate string
-
- MOV DX,82h ;point to first character in string
- MOV AH,9 ;
- INT 21h ;
-
- ; GET KEY FROM KEYBOARD
-
- AGAIN: ;re-entry point after unknown input
- MOV DI,OFFSET NORMAL_KEYS ;assume non-extended (normal) key
- MOV CX,NK_LEN
-
- MOV AH,7 ;
- INT 21h ;wait for a key
- CMP AL,0 ;extended ASCII?
- JNE A20 ; no, skip
- MOV AH,7 ; yes,
- INT 21h ; fetch the scan code into AL
- MOV DI,OFFSET FN_KEYS ; and set up for extended ASCII table
-
- A20: SCASB ;is AL in key table?
- JZ A30 ; yes, we're done
- INC DI ; no, skip past return code in table
- INC DI ; and past display byte
- LOOP A20 ; and try next elemetn
-
- CALL BEEP ;not found, so beep
- JMP AGAIN ; and restart
-
- ; DISPLAY THE CHARACTER
-
- A30: MOV DL,[DI+1] ;it was found
- MOV AH,2 ;so display the character
- INT 21h ;
-
- CALL CRLF ;and linefeed carriage-return
-
- MOV AL,[DI] ;fetch the return code
-
- MOV AH,4Ch ;
- INT 21h ;return AL as error level
-
- ASK ENDP
-
- ;------------------------------------------------------------------------
- ; BEEP near procedure ;
- ; sounds a beep by 'printing' an ASCII 7 (BEL character) ;
- ; all registers preserved ;
- ;------------------------------------------------------------------------
- BEEP PROC NEAR
- PUSH AX
- PUSH DX
- MOV AH,2
- MOV DL,7 ;BEL character
- INT 21h
- POP DX
- POP AX
- RET
- BEEP ENDP
-
- ;------------------------------------------------------------------------
- ; CRLF near procedure ;
- ; displays a linefeed and carriage-return ;
- ; all registers preserved ;
- ;------------------------------------------------------------------------
- CRLF PROC NEAR
- PUSH AX
- PUSH DX
- MOV AH,2
- MOV DL,0Dh ;CR character
- INT 21h
- MOV AH,2
- MOV DL,0Ah ;LF character
- INT 21h
- POP DX
- POP AX
- RET
- CRLF ENDP
-
- CODE ENDS
- END ASK